class HoldingFutures:
    futures = ""
    case = 1  # 1涨 -1跌
    pry = 1  # 买入杠杆
    num = 0  # 持有数量
    buyPrice = 0.0  # 买入单价
    buyAllPrice = 0.0  # 买入总价
    value = 1.0  # 目前价值 剩余价值
    profit = 0.0  # 利润
    profitRatio = 0.0  # 利润率

    lockNum = 0.0

    def __init__(self, futures, num, buyPrice, case, pry):
        self.futures = futures
        self.case = case
        self.buyPrice = buyPrice
        self.pry = pry
        self.num = num

        self.value = buyPrice * num
        self.buyAllPrice = buyPrice * num

    def reload(self):
        self.buyAllPrice = self.buyPrice * (self.num + self.lockNum)
        if self.value > 0:
            self.profit = (self.futures.nowPrice - self.buyPrice) / \
                          self.buyPrice * self.case * self.buyAllPrice * self.pry  # 计算涨幅
            self.profitRatio = self.profit / self.buyAllPrice  # 涨幅比
            self.value = self.buyAllPrice + self.profit  # 目前价值

            if self.value <= 0:  # 亏不超过本金
                self.profit = -self.buyAllPrice
                self.value = 0
                self.profitRatio = -1
            return

        self.profit = -self.buyAllPrice
        self.value = 0


class HoldingStock:
    stock = ""
    num = 0
    lockNum = 0.0
    buyPrice = 0.0  # 买入单价
    buyAllPrice = 0.0  # 买入总价
    profit = 0.0  # 利润
    profitRatio = 0.0  # 利润率

    def __init__(self, stock, num, buyPrice):
        self.stock = stock
        self.num = num
        self.buyPrice = buyPrice

    def reload(self):
        self.profit = (self.stock.nowPrice - self.buyPrice) * self.num
        self.buyAllPrice = self.buyPrice * self.num
        self.profitRatio = self.profit / self.buyAllPrice

    def addNum(self, num, price):
        if num == 0:
            return
        self.buyPrice = (price + self.buyPrice) / 2
        self.num += num
